/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package ua.yandex.skipass;

import java.util.Calendar;
import java.util.GregorianCalendar;

/**
 *
 * @author Neophron
 */
public class Turnstile {

    private final SkiPassSystem parent;
    
    private final Calendar calendar;

    public Turnstile(SkiPassSystem parent, Calendar calendar) {
        this.parent = parent;
        this.calendar = calendar;
    }

    public boolean open(Pass pass) {
        calendar.setTime(new GregorianCalendar().getTime());
        if (!parent.isPassBlocked(pass.getId())) {
            if (pass.allowTrip(calendar)) {
                parent.passed(pass.getId());
                return true;
            }
        }
        parent.notPassed(pass.getId());
        return false;
    }

    public void block(Pass pass) {
        parent.blockPass(pass.getId());
    }

}
